import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'

import { connect } from '@tarojs/redux'
import actions from '../../store/actions'

const { getList } = actions

@connect(({ getListData }) => ({
  getListData
}))
class Play extends Component {
  constructor(props) {
    super(props)
    this.state = {
      limit: 10,
      page: 1,
      type: 'addtime',
      day: 365
    }
  }

  config = {
    navigationBarTitleText: '列表'
  }

  componentDidMount() {
    const { getListData } = this.props
    getListData.data && getListData.data.length ? null : this.getData(0)
  }

  getData(more) {
    if (!this.props.getListData.hasMore) return
    const { dispatch } = this.props
    const { page, limit, type, day } = this.state
    dispatch(
      getList({
        limit,
        day,
        id: 3,
        order: type,
        p: page,
        more: more ? true : false
      })
    ).then(res => {
      // console.log(res)
    })
  }

  onReachBottom() {
    console.log('到底')
  }

  render() {
    return (
      <View style={{ height: 1000 }}>
        <Text>onReachBottom</Text>
      </View>
    )
  }
}

export default Play
